import 'package:flutter/material.dart';
import 'package:gw_github_flutter/common/global.dart';
import 'package:gw_github_flutter/common/notifier.dart';
import 'package:gw_github_flutter/generated/l10n.dart';
import 'package:provider/provider.dart';

class ThemeRoute extends StatefulWidget {
  ThemeRoute({Key? key}) : super(key: key);

  @override
  State<ThemeRoute> createState() => _ThemeRouteState();
}

class _ThemeRouteState extends State<ThemeRoute> {
  @override
  Widget build(BuildContext context) {
    var local = S.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(local.theme),
      ),
      body: _bodyW(),
    );
  }

  Widget _bodyW() {
    return ListView.separated(
      itemCount: Global.themes.length,
      separatorBuilder: (context, index) => Divider(
        height: .0,
      ),
      itemBuilder: (context, index) {
        return GestureDetector(
          child: Padding(
            padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 16),
            child: Container(
              color: Global.themes[index],
              height: 80,
            ),
          ),
          onTap: () {
            Provider.of<ThemeModel>(context, listen: false).theme =
                Global.themes[index];
          },
        );
      },
    );
  }
}
